var _serviceURL = '/69mark/merchant';// 必须设置

$(function() {
	
	doPage(1);
	
});

function doPage(page){
	var name = $("#serchName").val();
	var shopId = $("#shopId").val();
	$.ajax({
   		type : "POST",
   		url : _serviceURL+"/toListAllCoupon.do",
   		cache : false,
   		data : "pageNo="+page+"&pageSize=10&name="+name+"&shopId="+shopId,
   		dataType : 'json',
   		success : function(data) {
   			var result = "";
   			for(var i=0;i<data.menuList.length;i++){
   				result += "<div class=\"individual-form-home_record-table-demo-display\">";
   			    result += "<div class=\"individual-form-home_record-table-demo-display-state\">";
		        if (data.menuList[i].shelvesState == 1) {
   					result += "展示中";
                }else if (data.menuList[i].shelvesState == 3) {
                	result += "活动过期";
                }else {
                    result += "失效";
                }
		        result += "</div>";
   			    result += "<div class=\"individual-form-home_record-table-demo-display-heading\">";
		        result += ""+data.menuList[i].title+"</div>";
   			    result += "<div class=\"individual-form-home_record-table-demo-display-time\">";
		        result += ""+data.menuList[i].createdTime.substring(0,10)+" </div>";
   			    result += "<div class=\"individual-form-home_record-table-demo-display-operation\">";
		        result += "<div class=\"individual-form-home_record-table-demo-display-operation-modify\">";
	            result += "<a href=\"javascript:;\" onclick=\"tanchu("+data.menuList[i].bId+")\">";
                result += "查看  ";
                result += "</a>";
                
                if (data.menuList[i].shelvesState != 3) {
                	if (data.menuList[i].shelvesState == 1) {
    	            	result += "<a href=\"javascript:;\" onclick=\"updateState("+data.menuList[i].bId+",2)\">";
    	            	result += "下架";
    		        }else {
    		        	result += "<a href=\"javascript:;\" onclick=\"updateState("+data.menuList[i].bId+",1)\">";
    		            result += "上架";
    		        }
    		            
    	            result += "</a>";
                }
	            
		        result += "</div>";
   			    result += "</div>";
   			    result += "</div>";
   			    result += "<div class=\"individual-form-discount_record-table-demo-hide form-hide\" id="+data.menuList[i].bId+">";
   			    result += "<div class=\"individual-form-discount_record-table-demo-hide-bk\">";
		        result += "<span class=\"span01\">活动时间：</span>";
		        result += "<span class=\"span02\">"+data.menuList[i].startDate+" 至 "+data.menuList[i].endDate+"</span>";
		        result += "<br />";
		        
		        result += "<span class=\"span01\">优惠券时间：</span>";
		        result += "<span class=\"span02\">"+data.menuList[i].couponStartDate+" 至 "+data.menuList[i].couponEndDate+"</span>";
		        result += "<br />";
		        
		        result += "<span class=\"span01\">总数：</span>";
		        result += "<span class=\"span02\">"+data.menuList[i].num+"</span>";
		        result += "<span class=\"span01\">剩余数量：</span>";
		        
		        result += "<span class=\"span02\">"+data.menuList[i].numNumber+"</span>";
		        result += "<span class=\"span01\">金额：</span>";
		        result += "<span class=\"span02\">"+data.menuList[i].money+"</span>";
		        result += "<br />";
		        result += "<span class=\"span01\">使用规则：</span>";
		        result += "<span class=\"span02\">"+data.menuList[i].content+"</span>";
		        result += "</div>";
   			    result += "<div class=\"clear1\"></div>";
   			    result += "</div>";
   			    result += "<div class=\"clear\"></div>";
   				
   			}
   			
   			$("#heightList").html(result);
   			$("#page_user").html(data.navi);
   			
   			//新增属性值赋值为空
   			$("#name").val("");
   		}
	})
}

//查看
function tanchu(id) {
    $("#"+id).toggle();
}

function updateState(id,state){
	
	$.ajax({
        type:'POST',
        url:_serviceURL+'/updateCouponState.do',
        data:'id='+id+"&state="+state,
        dataType : 'json',
        success:function(data){
            if(data==1){
                doPage(1);
            }else{
                alert("修改失败");
            }
        }
    });
	
}



